package com.naiterui.ehp.bs.esign.config;

import com.naiterui.common.redis.RedisUtil;
import com.naiterui.ehp.bp.constants.CommonConstant;
import com.naiterui.ehp.bp.constants.EsignServiceProviderEnum;
import com.naiterui.ehp.bs.esign.api.ISignService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

/**
 * @Description 启动初始化内容
 * @Author gongbaoqiang
 * @Date 2020/7/31 3:11 PM
 */
@Slf4j
@Component
@Order(1)
public class EsignInitApplicationRunner implements ApplicationRunner {

    @Autowired
    private ISignService signService;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        EsignServiceProviderEnum serviceProvider = signService.getCurrentServiceProvider();
        //缓存签名方式配置
        RedisUtil.valueOps().setString(CommonConstant.ESIGN_SERVICE_NAME_KEY, serviceProvider.getServiceId());
        //缓存签章样式：1(方章)、2（手写）
        RedisUtil.valueOps().setString(CommonConstant.ESIGN_SEAL_TYPE_KEY, serviceProvider.getSealType().getType());
        log.info("初始化签署配置缓存-设置签名厂商缓存配置完成, provider:{}, sealType:{}", serviceProvider.getProviderName(), serviceProvider.getSealType().getName());

    }
}
